<?php
/**
 * TeacherModel.class.php
 * 教师模型
 * 
 * @author 	王中艺	<wangzy_smile@qq.com>
 * @date 	2017-03-03
 */
namespace Admin\Model;
use Think\Model;

class TeacherModel extends Model {
	protected 	$trueTableName = 't_teacher';
	public 	$errMsg 	= false;

	/**
	 * 获取列表
	 * @param   $page false:返回所有教师
	 * @param   $pageHtml 引用HTML
	 * @return  $list
	 */
	function getList($page, &$pageHtml){
		if($page === false){
			$list 	= $this->cache(true)->where('status != -1')->select();
			return $list;
		}

		$list 	= $this->where('status != -1')
			->order('id desc')
			->page($page, C('PAGE_COUNT'))
			->cache(true)
			->select();
		foreach($list as &$item){
			$item['sim_decipt']	= msubstr($item['decipt'], 0, 10);
			$item['create_date']	= date('Y-m-d', $item['create_time']);
			$item['sex_text']	= C('MEMBER_SEX.'.$item['sex']);
		}

		if($pageHtml){
			$count 	= $this->where('status != -1')->cache(true)->count();
			$Page 	= new \Think\Page($count, C('PAGE_COUNT'));
			$pageHtml 	= $Page->angular_show();
		}
		
		return $list;
	}

	/**
	 * 添加教师
	 * @param   $name 名称
	 * @param   $decipt 描述
	 * @param   $sex 性别
	 * @param   $phone 手机号
	 * @return  boolean [<description>]
	 */
	function addItem($name, $decipt, $sex, $phone){
		$info 	= array(
			'name'	=> $name,
			'decipt'	=> $decipt,
			'sex'	=> $sex,
			'phone'	=> $phone,
			'create_time'	=> time()
		);
		
		$teacherId	= $this->add($info);
		return $teacherId;
	}

	/**
	 * 变更教师
	 * @param   $teacherId 教师ID
	 * @param   $teacerInfo 教师信息
	 * @return  boolean [<description>]
	 */
	function change($teacherId, $teacherInfo){
		$result 	= $this->where('id = %d', $teacherId)->save($teacherInfo);
		return $result;
	}

	/**
	 * 删除教师
	 * @param   $teacherId 教师ID
	 * @return  boolean
	 */
	function deleteItem($teacherId){
		$info 	= array(
			'id'	=> $teacherId,
			'status'	=> -1
		);
		$result 	= $this->save($info);
		return $result;
	}
}